<?php

namespace plugin\enterprise\app\controller;

use plugin\enterprise\app\Enterprise;
use plugin\enterprise\app\service\EnterpriseRoleService;
use plugin\enterprise\app\service\EnterpriseUserService;
use plugin\owladmin\app\renderer\Form;
use plugin\owladmin\app\service\AdminRoleService;

class EnterpriseUserController extends \plugin\owladmin\app\controller\AdminUserController
{
    protected string $serviceName = EnterpriseUserService::class;
    public function __construct()
    {
        parent::__construct();
        $this->adminPrefix = Enterprise::config('enterprise.route.prefix');
        $this->queryPath = str_replace($this->adminPrefix . '/', '', request()->path());
    }



    public function form(): Form
    {
        return $this->baseForm()->body([
            amis()->ImageControl('avatar', admin_trans('admin.admin_user.avatar'))->receiver($this->uploadImagePath()),
            amis()->TextControl('username', admin_trans('admin.username'))->required(),
            amis()->TextControl('name', admin_trans('admin.admin_user.name'))->required(),
            amis()->TextControl('password', admin_trans('admin.password'))->type('input-password'),
            amis()->TextControl('confirm_password', admin_trans('admin.confirm_password'))->type('input-password'),
            amis()->SelectControl('roles', admin_trans('admin.admin_user.roles'))
                ->searchable()
                ->multiple()
                ->labelField('name')
                ->valueField('id')
                ->joinValues(false)
                ->extractValue()
                ->disabledOn('${id == 1}')
                ->options(EnterpriseRoleService::make()->query()->get(['id', 'name'])),
            amis()->SwitchControl('enabled', admin_trans('admin.extensions.card.status'))
                ->onText(admin_trans('admin.extensions.enable'))
                ->offText(admin_trans('admin.extensions.disable'))
                ->disabledOn('${id == 1}')
                ->value(1),
        ]);
    }
}